package cloud.topdaddy.admin.login.controller;

import cloud.topdaddy.admin.login.entity.LoginEntity;
import cloud.topdaddy.admin.login.service.LoginService;
import cloud.topdaddy.base.common.resp.R;
import cn.dev33.satoken.stp.StpUtil;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpSession;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

/**
 * 登录控制器
 *
 * @author topdaddy
 * @since 2025-07-01 14:22:43
 */
@RestController
@AllArgsConstructor
@RequestMapping("/auth")
@Tag(name = "login", description = "登录")
public class LoginController {

    private final LoginService loginService;

    @PostMapping("/login")
    public R<Map<String, Object>> login(@RequestBody @Valid LoginEntity loginEntity, HttpSession session) {
        return loginService.login(loginEntity, session);
    }

    @PostMapping("/logout")
    public R<String> logout() {
        StpUtil.logout();
        return R.ok("退出成功");
    }
}
